
<!--A Design by W3layouts
Author: W3layout
Author URL: http://w3layouts.com
License: Creative Commons Attribution 3.0 Unported
License URL: http://creativecommons.org/licenses/by/3.0/
-->
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html>
<head>
<title>iQ Online Survey System| Home </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link href="css/style.css" media="all" rel="stylesheet" type="text/css" />
</head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){

  var serverAddress = '127.0.0.1';
	
  $("#create_survey").click(function(){
	  var status_id=1;
	  var user_id=2;
	  var survey_name= document.getElementById("survey_name").value;
	
    var request = $.ajax({
        url: "http://" + serverAddress + "/soen-6461-server/survey/create",
        type: "post",
        data : {
				"Surveys[title]": survey_name, 
				"Surveys[creator_user_id]" : user_id,
				"Surveys[status_id]": status_id
			}
    });
	
	request.done(function (response, textStatus, jqXHR){
		//$('#response').text((JSON.stringify(response)));
		document.getElementById("survey_id").value=response.data.id;
		if(response.code==100)
		{
			document.getElementById("qestion_type").style="visibility: visible";
		}
		else if (response.code==-100)
		{
			//$('#response').text((JSON.stringify(response)));
	document.getElementById("response").innerHTML="error could not create survey";
		}
        
    });
	
  });
});
</script>
<script language="javascript">

function option()
{
	var choice =document.getElementById("options").value;
	if(choice==1)
	{
		document.getElementById("question_div").style="visibility: visible";
		document.getElementById("answers").style="visibility: visible";
	}
	else if(choice==2)
	{
			document.getElementById("question_div").style="visibility: visible";
		document.getElementById("answers").style="visibility: visible";	

	}
	else if(choice==3)
	{
			document.getElementById("question_div").style="visibility: visible";
		document.getElementById("answers").style="visibility: hidden";
	}
	else 
	{
		window.alert("Error");
	}
	
}
</script>
<script language="javascript">
$(document).ready(function(){
  $("#add_Q").click(function(){
	    var serverAddress = '127.0.0.1';
  
  var survey_id=document.getElementById("survey_id").value;
  var question_type=document.getElementById("options").value;
	var question= document.getElementById("question").value;
	var ans1=document.getElementById("answer1").value;
	var ans2=document.getElementById("answer2").value;
	var ans3=document.getElementById("answer3").value;
	var ans4=document.getElementById("answer4").value;
	
    var request = $.ajax({
        url: "http://" + serverAddress + "/soen-6461-server/surveyQA/create",
        type: "post",
        data : {
				"SurveyQA[Question][survey_id]": survey_id, 
				"SurveyQA[Question][text]" : question,
				"SurveyQA[AnswerChoices][0][text]":ans1,
"SurveyQA[AnswerChoices][0][ui_control_type_id]":question_type,
				"SurveyQA[AnswerChoices][1][text]":ans2,
"SurveyQA[AnswerChoices][1][ui_control_type_id]":question_type,
				"SurveyQA[AnswerChoices][2][text]":ans3,
"SurveyQA[AnswerChoices][2][ui_control_type_id]":question_type,
				"SurveyQA[AnswerChoices][3][text]":ans4,
"SurveyQA[AnswerChoices][3][ui_control_type_id]":question_type
			}

    });
	request.done(function (response, textStatus, jqXHR){
      //  $('#add_response').text(JSON.stringify(response));
		if(response.code==100)
		{
			document.getElementById("add_response").innerHTML="Question and answers has been added"
			document.getElementById("question").value='';
			document.getElementById("answer1").value='';
			document.getElementById("answer2").value='';
			document.getElementById("answer3").value='';
			document.getElementById("answer4").value='';
		}
		else if(response.code==100)
		{
			document.getElementById("add_response").innerHTML="error could not add Question";
		}
    });
	
  });
  });

</script>
<body>
<div class="header-bg">
<div class="wrap">
	<div class="header">
		<div class="logo">
		  		<a href="index.html"><b><font color="#00FF33" size="+3">iQ Online Survey System</font></b> </a>
		 </div>
	<div class="drp-dwn">
	 	<select onchange="window.location=this.options[this.selectedIndex].value">
			<option value="index.html">Home</option>
			<option value="signin.html">Signin</option>
			<option value="participate_in_survey.html">Participate In survey </option>
			<option value="about.html">About</option>
		</select>
	</div>
	 <div class="clear"></div>
	</div>
</div>
</div>
<div class="fluid_container">
<div id"create">

</div>
<h2> Create a Survey</h2>
  <form id="form1" method="post" action="">
    <p>&nbsp;</p>
    <p>
      <label for="survey_name">Enter Survey name </label>
      <input type="text" name="survey_name" id="survey_name" />
      <input type="button" name="create_survey" id="create_survey" value="Create"  />
    </p>

    <div id="response">
      <input type="text" id="survey_id" style="visibility:hidden" />
    </div>
    <p>&nbsp;</p>
    <div id="qestion_type" style="visibility:hidden">
  <select style="float:left" name="options" id="options" onchange="option();">
    <option> Choose Question Type</option>
      <option value="1">Single Answer Question</option>
      <option value="2">Multiple Answers Question </option>
      <option value="3">Short Answer Question</option>
    </select>
    </div>
    <div id="question_div" style="visibility:hidden">
     <p>&nbsp;</p>
      <p>&nbsp;      </p>
      <p>
        <label for="question"style="float:left">Enter the Question</label>
        <input name="question" type="text" id="question" style="float:left" />
      </p>
      <p>&nbsp; </p>
    </div>
    <div id="answers" style="visibility:hidden">
    <p>&nbsp;</p>
      <p >Enter Answers:</p>
      <p>&nbsp;</p>
      <p>
        <label for="s-answer1">Answer-1</label>
        <input type="text" name="answer1" id="answer1" value="" />
      </p>
      <p>
        <label for="answer2">Answer-2</label>
        <input type="text" name="answer2" id="answer2" value=""/>
      </p>
      <p>
        <label for="answer3">Answer-3</label>
        <input type="text" name="answer3" id="answer3"value="" />
      </p>
      <p>
        <label for="answer4">Answer-4</label>
        <input type="text" name="answer4" id="answer4" value=""/>
      </p>
 </div>
  
    <p>&nbsp;</p>
    <div id="add_response">
    </div>
    
    <p>&nbsp;</p>
    <p>
      <input type="button" name="submit" id="submit" value="Finish" style="float:right" onclick="window.location.href='user_page.html'" />
      <input type="button" name="cancel" id="cancel" value="Cancel" onclick="window.location.href='user_page.html'" style="float: left"/>
      <input type="button" name="add_Q" id="add_Q" value="ADD" style="float:right" />
      
    </p>
  </form>
  <p>&nbsp;</p>
 
</div>
<div class="footer-bg">
<div class="wrap">
<div class="footer">

		<div class="f_grid1">
			<ul class="f_nav">
				<li class="active"><a href="index.html">Home</a></li>
				<li><a href="signin.html">Signin</a></li>
				<li><a href="participate_in_survey.html">Participate In survey</a></li>
				<li><a href="about.html">About</a></li>
			</ul>
			<div class="copy">
				<p class="w3-link">© All Rights Reserved | Design by&nbsp; <a href="http://w3layouts.com/"> W3Layouts</a></p>
			</div>
			<div class="clear"></div>
		</div>
</div>
</div>
</div>
</body>
</html>